package main

import (
	"demo/es"
	"fmt"
)

func IndexCity() {
	var citys = []es.City{
		{"0001", "北京", "北京", []float64{39.91667, 116.41667}},
		{"0002", "天津", "天津", []float64{39.13333, 117.20000}},
		{"0003", "香港", "香港", []float64{22.20000, 114.10000}},
		{"0004", "广州", "广东", []float64{23.16667, 113.23333}},
		{"0005", "珠海", "广东", []float64{22.30000, 113.51667}},
		{"0006", "深圳", "广东", []float64{22.61667, 114.06667}},
		{"0007", "杭州", "浙江", []float64{30.26667, 120.20000}},
		{"0008", "重庆", "重庆", []float64{29.56667, 106.45000}},
		{"0009", "青岛", "山东", []float64{36.06667, 120.33333}},
		{"0010", "厦门", "福建", []float64{24.46667, 118.10000}},
		{"0011", "福州", "福建", []float64{26.08333, 119.30000}},
		{"0012", "兰州", "甘肃", []float64{36.03333, 103.73333}},
		{"0013", "贵阳", "贵州", []float64{26.56667, 106.71667}},
		{"0014", "长沙", "湖南", []float64{28.21667, 113.00000}},
		{"0015", "南京", "江苏", []float64{32.05000, 118.78333}},
		{"0016", "沈阳", "辽宁", []float64{41.80000, 123.38333}},
		{"0017", "成都", "四川", []float64{30.66667, 104.06667}},
	}

	for _, city := range citys {
		es.IndexCity(&city)
	}
}

func IndexCityBatch() {
	var citys = []*es.City{
		&es.City{"0001", "北京", "北京", []float64{39.91667, 116.41667}},
		&es.City{"0002", "天津", "天津", []float64{39.13333, 117.20000}},
		&es.City{"0003", "香港", "香港", []float64{22.20000, 114.10000}},
		&es.City{"0004", "广州", "广东", []float64{23.16667, 113.23333}},
		&es.City{"0005", "珠海", "广东", []float64{22.30000, 113.51667}},
		&es.City{"0006", "深圳", "广东", []float64{22.61667, 114.06667}},
		&es.City{"0007", "杭州", "浙江", []float64{30.26667, 120.20000}},
		&es.City{"0008", "重庆", "重庆", []float64{29.56667, 106.45000}},
		&es.City{"0009", "青岛", "山东", []float64{36.06667, 120.33333}},
		&es.City{"0010", "厦门", "福建", []float64{24.46667, 118.10000}},
		&es.City{"0011", "福州", "福建", []float64{26.08333, 119.30000}},
		&es.City{"0012", "兰州", "甘肃", []float64{36.03333, 103.73333}},
		&es.City{"0013", "贵阳", "贵州", []float64{26.56667, 106.71667}},
		&es.City{"0014", "长沙", "湖南", []float64{28.21667, 113.00000}},
		&es.City{"0015", "南京", "江苏", []float64{32.05000, 118.78333}},
		&es.City{"0016", "沈阳", "辽宁", []float64{41.80000, 123.38333}},
		&es.City{"0017", "成都", "四川", []float64{30.66667, 104.06667}},
	}

	es.IndexCityBatch(citys)
}

func SearchCity() {
	p := "广东"
	rect := es.Rectangle{TopLeft: es.Point{30, 110}, RightBottom: es.Point{20, 120}}

	citys := es.Search(p, &es.Point{22.30000, 113.51667}, &rect)
	for _, city := range citys {
		fmt.Printf("%#v\n", *city)
	}
}

func SearchCity2() {
	//珠海位置
	zhuhai := es.Point{22.30000, 113.51667}
	citys := es.SearchPoint(&zhuhai, "110km")
	for _, city := range citys {
		fmt.Printf("%#v\n", *city)
	}
}
